DXL attribute that returns "Object Level" = 2

Hello all,

 

I was hoping someone would be able to help.  My issue is I have requirements nestled under varying "Object Levels" and I want to return the "Object Heading" corresponding to the second Object Level.

 

For Example:

ID                                                   Level 2 Object Number

TSC - 0001     1             

TSC - 0010     1.1      

TSC - 0011     1.1.1

                        The TSC shall...      1.1

TSC - 0100     1.2

TSC - 0101      1.2.1

TSC - 0110      1.2.1.1

                         The TSC shall...      1.2

string r = null
string s = null 
string p = null

Object o = obj
string oh = o."Object Heading"
Object po = parent o
string isReq = o."Requirement"

if (isReq == "True") {
  
        p = po."Object Heading"

        //check if parent object heading is not empty
        if (p != null) {
          r = probeRichAttr_(po,"Object Number", false)
          displayRich r " " s
        
        }
}

What I have thus far simply returns the parent (of the given objects) Object Number, but I cant figure out how to write it so that the script will loop until it finds the corresponding level 2 object heading and return that one.

 

Any help will be much appreciated

 

Thanks

Mike


mwelch1280 - Fri Sep 18 10:29:47 EDT 2015

Re: DXL attribute that returns "Object Level" = 2
PekkaMakinen - Mon Sep 21 02:25:51 EDT 2015

Something like

 

// Text/String DXL attribute to show the Object Heading from the parent object at GotoLevel
Object po = null
int GotoLevel = 2
int ObjLevel = 0

// Do not process levels higher or same as that which we want to show
ObjLevel = level(obj)
if (ObjLevel <= GotoLevel)
{
  obj.attrDXLName = " "
  halt
}
// Use the while loop to climb up the object hierarchy
if (!null parent obj) po = parent obj
ObjLevel = level(po)
while (ObjLevel > GotoLevel)
{
  if (!null parent po) po = parent po
  ObjLevel = level(po)
}

// Now give value to the DXL attribute
if ((ObjLevel == GotoLevel) && (po."Object Heading" "" > ""))
{
  obj.attrDXLName = po."Object Heading" ""
}
else obj.attrDXLName = " "

Re: DXL attribute that returns "Object Level" = 2
mwelch1280 - Mon Sep 21 08:00:15 EDT 2015

PekkaMakinen, I will have to give it a try.

 

I am new to this whole thing and was able to accomplish what I what in an extremely inefficient manner (shown below).  

 

Thanks for giving me a template to work off of.

 

string s = null 

Object o = obj
string oh = o."Object Heading"
Object po = parent o
int L = level(Object o)
string isReq = o."Requirement"

if (isReq == "True") 
{

  if (L == 2)
  { 
    s = probeRichAttr_(o,"Object Number", false)
    displayRich s   
  }

  if(L ==3)
  {
    s = probeRichAttr_(parent o,"Object Number", false)
    displayRich s 
  }

  if(L ==4)
  {
    s = probeRichAttr_(parent parent o,"Object Number", false)
    displayRich s 
  }

  if(L ==5)
  {
    s = probeRichAttr_(parent parent parent o,"Object Number", false)
    displayRich s 
  }

}

 

Re: DXL attribute that returns "Object Level" = 2
llandale - Sat Sep 26 15:56:05 EDT 2015

Object GetParent(Object o, int parentLevel)

{   // Get the parent object that is at the specified level.

   // If this object is already at a higher level then return null

   // If this object is already at this level then return this object

   // *** RECURSION ENABLED ***

   if (null o)  then return(null Object)

   if (level(o) == parentLevel) then return(o)

   if (level(o) <= parentLevel) then return(null Object)

   return(GetParent(parent(o), parentLevel))   // ** RECURSION **

} // end GetParent()

bla bla bla

// Perhaps use it like this:

Object oParent = GetParent(o, 2)

if (null oParent) then oParent = o

string Paragraph = number(oParent)

// output Paragraph in your 3rd column

-Louie